<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/make_fun.png" alt />
        <span>后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主题区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '68px' : '200px'">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition='false'
          :router='true'
          :default-active="activePath"
        >
            <!-- 一级菜单 -->
          <el-submenu index="1">
              <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item index="/users" @click="saveNavState('/users')">
                <i class="el-icon-menu"></i>
                <span>用户列表</span>
            </el-menu-item>
          </el-submenu>

            <!-- 一级菜单 -->
          <el-submenu index="2">
              <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item index="2-1" @click="saveNavState('2-1')">
                <i class="el-icon-menu"></i>
                <span>导航一</span>
            </el-menu-item>
          </el-submenu>

            <!-- 一级菜单 -->
          <el-submenu index="3">
              <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item index="3-1" @click="saveNavState('3-1')">
                <i class="el-icon-menu"></i>
                <span>导航一</span>
            </el-menu-item>
          </el-submenu>

            <!-- 一级菜单 -->
          <el-submenu index="4">
              <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>订单管理</span>
            </template>
            <el-menu-item index="4-1" @click="saveNavState('4-1')">
                <i class="el-icon-menu"></i>
                <span>导航一</span>
            </el-menu-item>
          </el-submenu>

            <!-- 一级菜单 -->
          <el-submenu index="5">
              <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>数据统计</span>
            </template>
            <el-menu-item index="5-1" @click="saveNavState('5-1')">
                <i class="el-icon-menu"></i>
                <span>导航一</span>
            </el-menu-item>
          </el-submenu>
          
        </el-menu>
      </el-aside>
      <!-- 内容主体 -->
      <el-main>
          <!-- 路由器占位符 -->
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
    data(){
        return{
            isCollapse:false,
            // 被激活的链接地址
            activePath: ''
        }

    },
    created(){
        this.activePath=window.sessionStorage.getItem('activePath')
    },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 点击按钮，切换菜单的折叠与展开
    toggleCollapse(){
        this.isCollapse=!this.isCollapse
    },
    // 保存连接的激活状态
    saveNavState(activePath){
        window.sessionStorage.setItem('activePath',activePath)
        this.activePath=activePath
    }
  }
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    img {
      // display: inline-block;
      height: 60px;
    }
    span {
      padding-left: 10px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu{
      border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.toggle-button{
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>